package com.yn.xr.common.page;

import java.util.List;
import java.util.Map;


/**
 * 
 * @description:分页数据包装，包括分页信息和List数据      
 * @fileName:Page.java 
 * @createTime:2015年1月19日 下午6:03:45  
 * @author:肖震 
 * @version 1.0.0  
 *
 */
public class Page<T> implements java.io.Serializable
{
	/** 分页数据 **/
	private List<T> records;
	/** 页码开始索引和结束索引 **/
	private PageIndex pageIndex;
	/** 总页数 **/
	private int totalPage = 1;
	/** 每页显示记录数 **/
	private int maxResult = 1;
	/** 当前页 **/
	private int currentPage = 1;
	/** 总记录数 **/
	private int totalRecord;
	/** 每次显示多少页，必须保证大于3页，保证左右链接都可以使用 **/
	private int viewPageCount = 10;

	private String someStr;//其他字符
	
	private Map params; //传入的参数  
	private String orderColumn;  
    private String orderTurn = "ASC"; 
    
	public Page()
	{
		super();
	}

	/** 要获取记录的开始索引 **/
	public int getFirstResult()
	{
		return (this.currentPage - 1) * this.maxResult;
	}

	public int getViewPageCount()
	{
		return viewPageCount;
	}
	public Page(List<T> records, int totalPage,
			int maxResult, int currentPage, int totalRecord)
	{
		super();
		this.records = records;		
		this.totalPage = totalPage;
		this.maxResult = maxResult;
		this.currentPage = currentPage;
		this.totalRecord = totalRecord;
	}
	public void setViewPageCount(int viewPageCount)
	{
		this.viewPageCount = viewPageCount;
	}

	public Page(int maxResult, int currentPage)
	{
		this.maxResult = maxResult;
		this.currentPage = (currentPage <= 0 ? 1 : currentPage);
	}

	public Page(int currentPage)
	{
		this.currentPage = (currentPage <= 0 ? 1 : currentPage);
	}

	public void setQueryResult(PageResult<T> qr)
	{
		setTotalRecord(qr.getTotalRecord());
		setRecords(qr.getResultList());
	}

	public int getTotalRecord()
	{
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord)
	{
		this.totalRecord = totalRecord;
		setTotalPage(this.totalRecord % this.maxResult == 0 ? this.totalRecord / this.maxResult : this.totalRecord / this.maxResult + 1);
	}

	public List<T> getRecords()
	{
		return records;
	}

	public void setRecords(List<T> records)
	{
		this.records = records;
	}

	public PageIndex getPageIndex()
	{
		return pageIndex;
	}

	public int getTotalPage()
	{
		return totalPage;
	}

	public void setTotalPage(int totalPage)
	{
		this.totalPage = totalPage;
		this.pageIndex = PageIndex.getPageIndex(viewPageCount, currentPage, totalPage);
	}

	public int getMaxResult()
	{
		return maxResult;
	}

	public int getCurrentPage()
	{
		return currentPage;
	}

	
	public String getSomeStr()
	{
		return someStr;
	}

	
	public void setSomeStr(String someStr)
	{
		this.someStr = someStr;
	}

    public String getOrderColumn()
    {
        return orderColumn;
    }

    public void setOrderColumn(String orderColumn)
    {
        this.orderColumn = orderColumn;
    }

    public String getOrderTurn()
    {
        return orderTurn;
    }

    public void setOrderTurn(String orderTurn)
    {
        this.orderTurn = orderTurn;
    }

    public Map getParams()
    {
        return params;
    }

    public void setParams(Map params)
    {
        this.params = params;
    }
	
}
